<!DOCTYPE html>
<html lang="en">
<html><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="寞踪">
    <title>Lotus复制证明源码梳理 &middot; 寞踪的技术博客</title>
	<meta name="description" content="最开心的博客 Lotus复制证明源码梳理。"/>

    
    <link href="https://xpmozong.gitee.io/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://xpmozong.gitee.io/css/font-awesome.min.css" rel="stylesheet">
    <link href="https://xpmozong.gitee.io/css/animate.min.css" rel="stylesheet">
    <link href="https://xpmozong.gitee.io/css/blog.css" rel="stylesheet">
    <link href="https://xpmozong.gitee.io/css/responsive.css" rel="stylesheet">
    
	
		<link rel="shortcut icon" href="/images/favicon.ico">
	
</head><body><header id="header">
    <nav class="navbar navbar-inverse navbar-fixed-top" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/">
					
						<img src="/images/logo.png" alt="logo">
					
				</a>
            </div>

            <div class="collapse navbar-collapse navbar-right">
                <ul class="nav navbar-nav">
					
					
					
						
						
						<li  ><a href="/">首页</a></li>
						
					
						
						
						<li   class="active" ><a href="/posts">博客</a></li>
						
					
						
						
							<li class="dropdown ">
							    <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
									分类 <i class="fa fa-angle-down"></i>
								</a>
							    <ul class="dropdown-menu">
									
							        <li><a href="/categories/%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8">网络安全</a></li>
									
							        <li><a href="/categories/web3">web3</a></li>
									
							        <li><a href="/categories/lotus">lotus</a></li>
									
							    </ul>
							</li>
						
					
						
						
						<li  ><a href="/tags">标签</a></li>
						
					
						
						
						<li  ><a href="/about">关于我</a></li>
						
					
						
						
						<li  ><a href="/links">友情链接</a></li>
						
					
                </ul>
            </div>
        </div>
        
    </nav>
    
</header>

    <div class="page-title" style="background-image: url(https://xpmozong.gitee.io/images/page-title.jpg)">
        <h1>Single Blog</h1>
    </div>
    <section id="blog">
        <div class="blog container">
            <div class="row">
                <div class="col-md-8">
                    <div class="blog-item">
                        <div class="blog-content">
                            <h2>Lotus复制证明源码梳理</h2>
                            <div class="post-meta">
                                <p><i class="fa fa-clock-o"></i> October 18, 2022</p>
								<p>字数: 404</p>
                            </div>
                            <p>流程图</p>
<p><img src="work.jpg" alt="img"></p>
<h2 id="incoming">Incoming</h2>
<p>首先调用 PledgeSector 通过类似微服务的方式调用</p>
<p>在 cmd/lotus-miner/sectors.go 发出生成扇区的命令，通过微服务的方式调用</p>
<pre tabindex="0"><code>var sectorsPledgeCmd = &amp;cli.Command{
    Name:  &#34;pledge&#34;,
    Usage: &#34;store random data in a sector&#34;,
    Action: func(cctx *cli.Context) error {
        // 获取miner网关地址
        minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
        if err != nil {
            return err
        }
        defer closer()
        ctx := lcli.ReqContext(cctx)

        id, err := minerApi.PledgeSector(ctx)
        if err != nil {
            return err
        }

        fmt.Println(&#34;Created CC sector: &#34;, id.Number)

        return nil
    },
}
</code></pre><p>在 storage/pipeline/garbage.go 生成新的扇区,获取分片数组大小，扇区id，该过程关键在调用内部方法 m.pledgeSector产生数据，填满扇区数据。</p>
<pre tabindex="0"><code>func (m *Sealing) PledgeSector(ctx context.Context) (storiface.SectorRef, error) {
    m.startupWait.Wait()

    m.inputLk.Lock()
    defer m.inputLk.Unlock()

    cfg, err := m.getConfig()
    if err != nil {
        return storiface.SectorRef{}, xerrors.Errorf(&#34;getting config: %w&#34;, err)
    }

    if cfg.MaxSealingSectors &gt; 0 {
        if m.stats.curSealing() &gt;= cfg.MaxSealingSectors {
            return storiface.SectorRef{}, xerrors.Errorf(&#34;too many sectors sealing (curSealing: %d, max: %d)&#34;, m.stats.curSealing(), cfg.MaxSealingSectors)
        }
    }

    spt, err := m.currentSealProof(ctx)
    if err != nil {
        return storiface.SectorRef{}, xerrors.Errorf(&#34;getting seal proof type: %w&#34;, err)
    }

    sid, err := m.createSector(ctx, cfg, spt)
    if err != nil {
        return storiface.SectorRef{}, err
    }

    log.Infof(&#34;Creating CC sector %d&#34;, sid)
    return m.minerSector(spt, sid), m.sectors.Send(uint64(sid), SectorStartCC{
        ID:         sid,
        SectorType: spt,
    })
}
</code></pre><p>storage/pipeline/fsm.go</p>
<pre tabindex="0"><code>/*

    UndefinedSectorState (start)
           v                     |
    *&lt;- WaitDeals &lt;-&gt; AddPiece   |
    |   |   /--------------------/
    |   v   v
    *&lt;- Packing &lt;- incoming committed capacity
    |   |
    |   v
    |   GetTicket
    |   |   ^
    |   v   |
    *&lt;- PreCommit1 &lt;--&gt; SealPreCommit1Failed
    |   |       ^          ^^
    |   |       *----------++----\
    |   v       v          ||    |
    *&lt;- PreCommit2 --------++--&gt; SealPreCommit2Failed
    |   |                  ||
    |   v          /-------/|
    *   PreCommitting &lt;-----+---&gt; PreCommitFailed
    |   |                   |     ^
    |   v                   |     |
    *&lt;- WaitSeed -----------+-----/
    |   |||  ^              |
    |   |||  \--------*-----/
    |   |||           |
    |   vvv      v----+----&gt; ComputeProofFailed
    *&lt;- Committing    |
    |   |        ^--&gt; CommitFailed
    |   v             ^
        |   SubmitCommit  |
        |   |             |
        |   v             |
    *&lt;- CommitWait ---/
    |   |
    |   v
    |   FinalizeSector &lt;--&gt; FinalizeFailed
    |   |
    |   v
    *&lt;- Proving
    |
    v
    FailedUnrecoverable
*/
</code></pre>
                            
                            <div class="inner-meta block">
								
									
										<a href="https://xpmozong.gitee.io/tags/lotus">Lotus</a>
									
								
                            </div>
                        </div>
                    </div>
                    
					
                    <div class="paging">
                        
                          <div class="block previous"><a href="https://xpmozong.gitee.io/posts/%E4%BB%80%E4%B9%88%E6%98%AF-xss-%E6%94%BB%E5%87%BB/">&lt;- 什么是 XSS 攻击？</a></div>
                        
                        
                          <div class="block next"><a href="https://xpmozong.gitee.io/posts/lotus%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA%A6%E6%BA%90%E7%A0%81%E6%A2%B3%E7%90%86/"> Lotus任务调度源码梳理 -></a></div>
                        
                    </div>
					
                </div>
                
				
				<aside class="col-md-4">
					<div class="toc" id="mright">
						<div class="widget">
							<h3 class="widget-title section-title">目录</h3>
							<div class="row">
								<div class="col-sm-12 widget--toc">
									<nav id="TableOfContents">
  <ul>
    <li><a href="#incoming">Incoming</a></li>
  </ul>
</nav>
								</div>
							</div>
						</div>
					</div>
				</aside>
				
            </div>
            
        </div>
    </section>
    
<section id="bottom">
	<div class="container fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
		<div class="row">
			<div class="col-md-2">
				<a href="/" class="footer-logo">
					
						<img src="https://xpmozong.gitee.io/images/dark-logo.png" alt="logo">
					
				</a>
			</div>
			<div class="col-md-10">
				<div class="row">
					<div class="col-md-3 col-sm-6">
						<div class="widget">
							<h3>近期文章</h3>
							<ul>
								
								
									<li><a href="https://xpmozong.gitee.io/posts/lotus%E6%97%B6%E7%A9%BA%E8%AF%81%E6%98%8E%E6%BA%90%E7%A0%81%E6%A2%B3%E7%90%86/">Lotus时空证明源码梳理</a></li>
								
									<li><a href="https://xpmozong.gitee.io/posts/lotus%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA%A6%E6%BA%90%E7%A0%81%E6%A2%B3%E7%90%86/">Lotus任务调度源码梳理</a></li>
								
									<li><a href="https://xpmozong.gitee.io/posts/lotus%E5%A4%8D%E5%88%B6%E8%AF%81%E6%98%8E%E6%BA%90%E7%A0%81%E6%A2%B3%E7%90%86/">Lotus复制证明源码梳理</a></li>
								
									<li><a href="https://xpmozong.gitee.io/posts/%E4%BB%80%E4%B9%88%E6%98%AF-xss-%E6%94%BB%E5%87%BB/">什么是 XSS 攻击？</a></li>
								
									<li><a href="https://xpmozong.gitee.io/posts/csrf%E6%94%BB%E5%87%BB%E6%98%AF%E4%BB%80%E4%B9%88/">CSRF攻击是什么？</a></li>
								
							</ul>
						</div>
					</div>
					
					<div class="col-md-3 col-sm-6">
						<div class="widget">
							<h3>文章归档</h3>
							<ul>
								
									
								
								
								
								
								
								<li><a href="/archives#2022.10">2022.10</a></li>
								
							</ul>
						</div>
					</div>
					

					<div class="col-md-3 col-sm-6">
						<div class="widget">
							<h3>文章分类</h3>
							<ul>
								
									<li><a href="/categories/lotus/">Lotus(3)</a></li>
								
									<li><a href="/categories/%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8/">网络安全(2)</a></li>
								
							</ul>
						</div>
					</div>
					
					<div class="col-md-3 col-sm-6">
						<div class="widget">
							<h3>文章标签</h3>
							<ul>
								
									<li><a href="/tags/lotus/">Lotus(3)</a></li>
								
									<li><a href="/tags/%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8/">网络安全(2)</a></li>
								
							</ul>
						</div>
					</div>
					
				</div>
			</div>
		</div>
	</div>
</section>


<footer id="footer" class="midnight-blue">
    <div class="container">
        <div class="row">
            <div class="col-sm-6">
                &copy; 
				
					2020 - 
				
				2022
				
					寞踪 All Rights Reserved. <br/>
				
				
				
				
		
				Built with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> <br />
				主题 <b><a href="https://gitee.com/xpmozong/xpmozong" target="_blank" rel="noopener" data-version="%!s(MISSING)">Wave</a></b> 由 <a href="https://gitee.com/xpmozong" target="_blank" rel="noopener">寞踪</a> 设计
            </div>
            <div class="col-sm-6">
                <ul class="pull-right">
					
					
					
						
						<li  >
							<a href="/">首页</a>
						</li>
                    
						
						<li   class="active" >
							<a href="/posts">博客</a>
						</li>
                    
						
						<li  >
							<a href="/categories">分类</a>
						</li>
                    
						
						<li  >
							<a href="/tags">标签</a>
						</li>
                    
						
						<li  >
							<a href="/about">关于我</a>
						</li>
                    
						
						<li  >
							<a href="/links">友情链接</a>
						</li>
                    
                </ul>
            </div>
        </div>
    </div>
</footer>

<script src="https://xpmozong.gitee.io/js/jquery.js "></script>
<script src="https://xpmozong.gitee.io/js/bootstrap.min.js "></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.js"></script>
<script src="https://xpmozong.gitee.io/js/search.js"></script>
<script src="https://xpmozong.gitee.io/js/main.js"></script></body>
</html>
